home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / dosbasic.zip / ASM.ZIP / FEXIST.ASM < prev    next >
Assembly Source File  |  1990-12-19  |  7KB  |  177 lines

  1. ;«RM82»«TS8,16,24,32,40,48»
  2. ; Updated 11/24/90
  3.  
  4. ;============================================================================
  5. ;
  6. ;   Copyright (C) Copr. 1990 by Sidney J. Kelly
  7. ;           All Rights Reserved.
  8. ;           Sidney J. Kelly
  9. ;           150 Woodhaven Drive
  10. ;           Pittsburgh, PA 15228
  11. ;           home phone 412-561-0950 (7pm to 9:30pm EST)
  12. ;============================================================================
  13.  
  14. ;============================================================================
  15. ; DECLARE SUB EXIST (FILNAME$, ErrCode%, Mode%)
  16. ; CALL EXIST(FILENAME$+CHR$(0), ErrCode%, Mode%)
  17. ; Filename$ must be an ASCII Null string (end in CHR$(0)).
  18. ; Filename$ can not be a TYPEd string or a variable in a string array
  19. ; because there is a chance that string will be outside DGROUP.  String
  20. ; cocentenation is used to make sure it is in DGROUP.
  21. ;
  22. ; Mode%: 
  23. ;      =  0 if just want to see if file exits
  24. ;      <> 0 if want to see if can read and write to file
  25. ;
  26. ; Returns ErrCode%    = 0 (False) if no error
  27. ;                     = True if an error,
  28. ; Codes:
  29. ;      -1 = string wrong length
  30. ;       2 = file not found
  31. ;       3 = path not found
  32. ;       4 = no free handles
  33. ;       5 = access denied          (tried to read a subdirectory)
  34. ;      12 = invalid access code    (wont see this unless Mode% = 1)
  35. ;      20 = Write protect error    (wont see this)
  36. ;      21 = Invalid drive
  37. ;      22 = Drive not ready        (floppy drive door open)
  38. ;      23 = unknown command
  39. ;      24 = CRC error
  40. ;      25 = Bad request structure
  41. ;      26 = Seek error
  42. ;      27 = Unkown disk format
  43. ;      28 = Sector not found
  44. ;      29 = Printer out of paper   (shouldn't see this)
  45. ;      30 = Write fault            (shouldn't see this)
  46. ;      31 = Read fault
  47. ;      32 = General, non-specific error (usually a network drive error)
  48. ;      35 = Invalid Disk Change    (shouldn't see this)
  49. ;============================================================================
  50.  
  51. DOSSEG
  52. .MODEL MEDIUM
  53.     PUBLIC  EXIST
  54. .CODE
  55. ; Please do not remove
  56. Copyright       DB    13,10,'Copyright Copr. (C) 1990 Sidney J. Kelly',13,10
  57. Copyright1      DB    'All Rights Reserved',13,10,26
  58.  
  59. NAMESTRG        EQU     [BP+10]       ; easy memory jogger for stack names
  60. ERRCODE         EQU     [BP+8]        ; easy memory jogger for stack names
  61. MODE        EQU    [BP+6]          ; easy memory jogger for stack names
  62.  
  63. EVEN
  64. CE_Off          DW      0             ; to save space in DGROUP
  65. CE_Seg          DW      0             ; address of previos handler
  66. Last_Error      DW      0             ; store last error code
  67.  
  68. EVEN
  69. EXIST   PROC    FAR
  70.         Push    BP          ; save stack frame
  71.         Mov     BP,SP
  72.                       ; Change Vector
  73.         Mov     AX,3524h      ; use DOS to get current
  74.         Int     21h           ; address of the vector
  75.         Mov     CE_Seg, ES    ; save for removal
  76.         Mov     CE_Off, BX    ; address returned in ES:BX
  77.         Push    DS            ; hold DS a moment
  78.         Mov     AX,CS
  79.         Mov     DS,AX         ; set CS == DS
  80.  
  81.         Assume  DS:@code
  82.  
  83.         ;need this so offset is calculated with reference to 
  84.         ;CSEG rather than DGROUP
  85.  
  86.         Mov     DX, OFFSET CE ; get address of our MASM handler
  87.         Mov     AX, 2524h     ; tell DOS we're taking this vector
  88.         Int     21h           ; grab the vector
  89.         Pop     DS            ; restore DS
  90.  
  91.         Assume  DS:@data      ; tell MASM DS is restored
  92.  
  93.         Mov     AX,-1         ; assume an error
  94.         Mov     BX,NAMESTRG   ; get string descriptor
  95.         Mov     CX,[BX]       ; put length of string in CX
  96.         Jcxz    Finis         ; FILENAME$ is a null string so exit
  97.  
  98. comment |
  99.         ;This is an alternative routine, but because it does not
  100.         ;reset the DTA, it can cause problems with routines
  101.         ;that use the COMMAND$ inside QBASIC.  The default DTA
  102.         ;will overwrite the COMMAND$ storage area in the PSP.
  103.  
  104.         Mov     CX,100111b   ;search for all file types
  105.                      ;BUT volume and subdirectories
  106.         Mov     AX,4E00h     ;use FIND FIRST function
  107.         Int     21h
  108.         Jnc     FileFound
  109.         Mov     AX,-1        ;report error & quit
  110.         Jmp     Short fini
  111. FileFound:
  112.         Xor     AX,AX        ;report no error & quit
  113.     |
  114.  
  115.         Xor     AX,AX         ; assume no error
  116.         Mov     CS:[Last_Error],AX ; store it
  117.         Mov     DX,[BX+2]     ; get string address into DS:DX
  118.         Mov    BX,MODE
  119.         Mov    AX,[BX]          ; read MODE status
  120.         Or    AX,AX          ; is MODE = 0? (read only mode)
  121.         Jz    Open_Handle   ; yes, so skip ahead
  122.         Mov     AL,010b       ; load (read/write) access
  123. Open_Handle:
  124.         Mov    AH,3Dh        ;  open file handle 
  125.         Int     21h           ; sets carryflag if not found
  126.         Jnc     Looks_good    ; Could it be o.k. ?
  127.                       ; (Carry set if file not found)
  128.         Cmp     CS:[Last_Error],0   ; was this a CE err or normal err
  129.         JE      Finis         ; Normal, quit with error code from DOS
  130.         Jmp     Short Dos_Error   ; else quit with CE error
  131. Looks_good:
  132.         Cmp     CS:[Last_Error],0  ; did DOS report an error?
  133.                       ; this is a safety check
  134.         JE      File_Found    ; nope, so skip ahead
  135.         Jmp     Short Dos_Error   ; report an error occured, so quit
  136. File_Found:
  137.         Mov     BX,AX         ; if valid handle returned, store in BX
  138.         Mov     AH,3Eh        ; close file handle in BX, handle found
  139.         Int     21h           ; the following will trap a file close
  140.                       ; error
  141. Dos_Error:
  142.         Mov     AX,CS:[Last_Error] ; get last error message in AX
  143. Finis:
  144.         Mov     BX,ERRCODE
  145.         Mov     [BX],AX       ; store value of ErrCode%
  146.         Push    DS            ; Reset old CE vector
  147.         Mov     DX, CE_Off    ; get old values
  148.         Mov     AX, CE_Seg
  149.         Mov     DS, AX
  150.         Mov     AX, 2524h     ; SET VECTOR call
  151.         Int     21h           ; restore it
  152.         Pop     DS            ; restore registers
  153.         Pop     BP
  154.         Ret     6             ; remove the 3 (2 * 3) parameters
  155. EXIST   ENDP
  156.  
  157. ;===========================================================================
  158. ; Substitute critical error handler, does nothing but capture error.
  159. ; This would be unsafe for most routines but not here.
  160. ;===========================================================================
  161.  
  162. EVEN
  163. CE   PROC  FAR
  164.         Assume  DS:NOTHING, ES:NOTHING
  165.         Pushf                 ; save flags
  166.         Mov     AX,DI         ; get error code
  167.         Add     AX,20         ; add 20 to it (so can tell origen of
  168.                       ; error, CE or Function 03Dh)
  169.         Mov     CS:[Last_Error],AX   ; store error code
  170.         Xor     AL,AL         ; tell DOS to ignore error
  171.         Popf                  ; restore flags
  172.         Iret
  173.         Assume  DS:@data
  174. CE  ENDP
  175. END
  176.  
  177.